package com.hmall.common.domain;

import com.hmall.common.utils.CollUtils;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
public class MultiDelayMessage<T> {
    //要发送的消息内容
    private T data;
    //要延迟的时间片集合
    private List<Integer> delayMillis;

    public MultiDelayMessage(T data, List<Integer> delayMillis) {
        this.data = data;
        this.delayMillis = delayMillis;
    }

    //构建方法of
    public static <T> MultiDelayMessage<T> of(T data, Integer... delayMillis) {
        return new MultiDelayMessage<>(data, CollUtils.newArrayList(delayMillis));
    }

    //删除并获取第一个元素
    public Integer removeDelayMillis() {
        return this.delayMillis.remove(0);
    }

    //判断是否还有时间片元素
    public boolean hasNextDelayMillis() {
        return !this.delayMillis.isEmpty();
    }
}